<template>
  <div class="global-loading" v-show="isLoading">
    <a-spin :indicator="indicator" size="large" />
  </div>
</template>

<script setup>
import { useLoadingStore } from '../stores/loading';
import { computed, ref, watch } from 'vue';
import { LoadingOutlined } from '@ant-design/icons-vue';
import { h } from 'vue';

const loadingStore = useLoadingStore();
const isLoading = ref(false);
const currentLoading = computed(() => loadingStore.isLoading);

const indicator = h(LoadingOutlined, { style: 'font-size: 32px', spin: true });

watch(currentLoading, (newValue) => {
  if (newValue) {
    isLoading.value = true;
  } else {
    setTimeout(() => {
      isLoading.value = false;
    }, 2000); // 可以调整为 1000 毫秒
  }
});
</script>

<style scoped>
.global-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
}

.global-loading .ant-spin-nested-loading .ant-spin {
  color: white; /* 加载图标颜色 */
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); /* 添加阴影 */
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>